import { BaseComponent } from "../../../../shared/components/baseComponent/base.component";
import { ChangeDetectorRef } from "@angular/core";

export class CriteriaPermissionsComponent extends BaseComponent {
    
    constructor(permCdRef: ChangeDetectorRef){
        super(permCdRef);
    }

    public isEnabled(parentName: string, shortName: string): boolean {
        let resource: string = "api/v1/filters/{filterId}/criteria";
        let verb: string = 'POST';
        let name = shortName.toLowerCase();        
        if (shortName.indexOf('Global Compact Compliance') > -1)
            return this.hasPermission(resource, verb, [{ key: 'shortName', value: 'gccsnc' }]) ||
                this.hasPermission(resource, verb, [{ key: 'shortName', value: 'gccswl' }]);
        else if (name == 'sedol' || name == 'wkn' || name == 'valor')
            return this.hasPermission(resource, verb, [{ key: 'shortName', value: name }]);
        else if (parentName.toLowerCase() == 'pi')
            return this.hasPermission("api/v1/pi", verb, [{ key: 'pi', value: this.getParameterForPI(name) }]);
        else if (parentName.toLowerCase() == 'sp')
            return this.hasPermission("api/v1/sp", verb, [{ key: 'sp', value: this.getParameterForSP(name) }]);
        else
            return this.hasPermission(resource, verb, [{ key: 'shortName', value: parentName.toLowerCase() }]);
    }

    private getParameterForPI(shortName: string): string {
        let ret = shortName;
        switch (shortName) {
            case "adult entertainment": ret = "ae"; break;
            case "alcoholic beverages": ret = "al"; break;
            case "controversial weapons": ret = "cw"; break;
            case "small arms": ret = "fa"; break;
            case "fur and specialty leather": ret = "fl"; break;
            case "gambling": ret = "gb"; break;
            case "genetically modified plants and seeds": ret = "gm"; break;
            case "military contracting": ret = "mc"; break;
            case "nuclear": ret = "np"; break;
            case "pesticides": ret = "pe"; break;
            case "tobacco products": ret = "tp"; break;
            case "abortion": ret = "ab"; break;
            case "contraceptives": ret = "co"; break;
            case "human embryonic stem cell and fetal tissue": ret = "sc"; break;
            case "palm oil": ret = "pm"; break;
            case "pork products": ret = "pp"; break;
            case "animal testing": ret = "at"; break;
            case "predatory lending": ret = "pl"; break;
            case "thermal coal": ret = "tc"; break;
            case "oil sands": ret = "os"; break;
            case "arctic oil & gas exploration": ret = "ac"; break;
            case "cannabis":ret="cb"; break;
            case "oil & gas": ret="og"; break;
            case "riot control": ret="rc"; break;
            case "shale energy": ret="se"; break;
            case "whale meat": ret="wm"; break;
        };
        return ret;
    }

    private getParameterForSP(shortName: string): string {
        let ret = shortName;
        switch (shortName) {
            case "affordable housing": ret = "ah"; break;
            case "education": ret = "ed"; break;
            case "energy efficiency": ret = "ee"; break;
            case "financial inclusion": ret = "fi"; break;
            case "green buildings": ret = "gr"; break;
            case "green transportation": ret = "gt"; break;
            case "health": ret = "he"; break;
            case "pollution prevention & reduction": ret = "pr"; break;
            case "renewable energy": ret = "re"; break;
            case "resource efficiency": ret = "rs"; break;
            case "sustainable agriculture, food & forestry": ret = "sf"; break;
            case "water": ret = "wa"; break;
        };
        return ret;
    }
}